<?php
declare (strict_types = 1);

namespace app\validate;

use think\Validate;

class User extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
            'username' =>'require|unique:user|max:25',
            'password' =>'require|min:6|confirm:confirm',
            'email'=>'email',
//            'schoolEmail'=>['require', 'regex' => '/^[0-9]+@gdufs./'],
            'statement'=>'max:150',
            'sex'=>'number|between:0,2',
            'image'=>'filesize:1024000|fileExt:jpg,jpeg,png'
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'username.require'=>'用户名不得为空',
        'username.unique'=>'用户名已存在',
        'username.max'=>'用户名最大不超过25位',
        'password.require'=>'密码不得为空',
        'password.min'=>'密码最少达到6位',
        'password.confirm'=>'两次密码不正确',
        'email.email'=>'邮箱格式不正确',
        'schoolEmail'=>'学校邮箱格式不正确',
        'statement'=>'个人简介不超过150个字',
        'image.filesize'=>'头像文件过大',
        'image.fileExt'=>'头像后缀不符合要求',

    ];
    protected $scene = [
        'update'  =>  ['statement','sex'],
        'upload'  =>  ['image'],
        'passwordForget'=>['password']
    ];
}
